#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#include <set>
using namespace std;
const int N=1e5+5;
double poss(int v0,int a,int v1){
    return (double(v1*v1)-double(v0*v0))/double(2*a);
}
int up(double x){
    return int(x)+(x!=int(x));
}
int n,m,l,V;
int d[N],v[N],a[N];
int p[N];
vector<int> mu[N];
int f[N];
set<int> st;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--){
        for(int i=1;i<=m;i++)mu[i].clear();
        memset(f,0,sizeof(f));
        while(st.size())st.erase(st.begin());
        scanf("%d%d%d%d",&n,&m,&l,&V);
        for(int i=1;i<=n;i++){
            scanf("%d%d%d",&d[i],&v[i],&a[i]);
        }
        for(int i=1;i<=m;i++){
           scanf("%d",&p[i]);
        }
        int ans1=0;
        for(int i=1;i<=n;i++){
            if(d[i]>p[m])continue;
            if(a[i]==0){
                if(v[i]<=V)continue;
                int ls=lower_bound(p+1,p+m+1,d[i])-p;
                mu[ls].push_back(i);
                mu[m].push_back(-i);
                ans1++;
            }else{
                if(v[i]<=V && a[i]<0)continue;
                double vs=poss(v[i],a[i],V)+double(d[i]);
                if(vs>=p[m] && a[i]>0)continue;
                int ls,rs;
                if(a[i]>0){
                    ls=upper_bound(p+1,p+m+1,int(vs))-p;
                    rs=m;
                }else{
                    ls=lower_bound(p+1,p+m+1,d[i])-p;
                    rs=vs>p[m]?m:lower_bound(p+1,p+m+1,up(vs))-p-1;
                }
                if(ls>rs || rs<1 || ls>m)continue;
                mu[ls].push_back(i);
                mu[rs].push_back(-i);
                ans1++;
            }
        }
        printf("%d ",ans1);
        if(ans1==0){
            printf("%d\n",m);
            continue;
        }
        int ans2=0;
        for(int i=1;i<=m;i++){
            bool flag=true;
            for(int j=0;j<mu[i].size();j++){
                if(mu[i][j]<0){
                    st.erase(-mu[i][j]);
                    if(f[-mu[i][j]]==0)flag=false;
                }else if(mu[i][j]>0)st.insert(mu[i][j]);
            }
            if(!flag){
                ans2++;
                for(set<int>::iterator it=st.begin();it!=st.end();it++){
                    f[*it]++;
                }
            }
        }
        printf("%d\n",m-ans2);
    }
    return 0;
}
